<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>配置管理系统</title>
</head>
<body>
    <!-- 为ECharts准备一个具备大小（宽高）的Dom -->
    <div id="main" style="height:600px"></div>

	<link rel="stylesheet" href="{{ STATIC_URL }}css/jquery-ui.min.css">
	<script src="{{ STATIC_URL }}js/jquery.min.js"></script>
	<script src="{{ STATIC_URL }}js/jquery-ui.min.js"></script>
	<link rel="stylesheet" href="{{ STATIC_URL }}css/style.css">
    <!-- ECharts单文件引入 -->
    <script src="{{ STATIC_URL }}js/echarts.js"></script>

<div id="dialog" title="环境连接关系" >
	<p></p>
	</div>


    <script type="text/javascript">
        // 路径配置
		$(function() {
			$( "#dialog" ).dialog({
				width: 700,
				
			  autoOpen: false,
			  show: {
				effect: "blind",
				duration: 1000
			  },
			  hide: {
				effect: "explode",
				duration: 1000
			  }
			 
			
			});
			
		  });
		function displaydetail(){
            
			$("p").toggle();
        }
    
		  

		
        require.config({
            paths: {
                echarts: '{{ STATIC_URL }}js/build/dist'
            }
        });
        
        // 使用
        require(
            [
                'echarts',
                'echarts/chart/force' // 使用力导向布局图就加载force模块，按需加载
            ],
            function (ec) {
                // 基于准备好的dom，初始化echarts图表
                var myChart = ec.init(document.getElementById('main')); 
		
        
        var option = {
    title : {
        text: '{{request_node_name_envi}}及其相关环境对接关系',
        x:'right',
        y:'bottom'
    },

    toolbox: {
        show : true,
        feature : {
            restore : {show: true},
            //magicType: {show: true, type: ['force', 'chord']},
            saveAsImage : {show: true}
        }
    },
    
    tooltip : {
        trigger: 'item',
        formatter: function (params,ticket,callback) {
            console.log(params)
            var res = "<p>"+"节点详细信息"+"</p>"+
            "<table border='1'><tr><th>系统名</th><th>IP及服务器信息</th></tr>";
            ips = params.data.ip.split("|")
       
            
            for (var i = 0, l = ips.length; i < l; i++) {
            	res += "<tr><th>"+params.data.name+"</th>"
            	res += "<th>"+ips[i]+"</th></tr>";
            }            
            
            res += "</table>";
            setTimeout(function (){
                // 仅为了模拟异步回调
                callback(ticket, res);
            }, 200)
            return 'loading';
        }
    },
    
    legend: {
        x: 'left',
        data:['主环境','关联环境']
    },
    series : [
        {
            type:'force',
            categories : [
                {
                    name: '主环境'
                },
                {
                    name: '关联环境'
                }
            ],
            name : "{{out_title}}间关系",
            ribbonType: false,
     
            itemStyle: {
                normal: {
                    label: {
                        show: true,
                        textStyle: {
                            color: '#333'
                        }
                    },
                    nodeStyle : {
                        brushType : 'both',
                        borderColor : 'rgba(255,215,0,0.4)',
                        borderWidth : 1
                    },
                    linkStyle: {
                        type: 'curve'
                    }
                },
                emphasis: {
                    label: {
                        show: false
                        // textStyle: null      // 默认使用全局文本样式，详见TEXTSTYLE
                    },
                    nodeStyle : {
                        //r: 30
                    },
                    linkStyle : {}
                }
            },
            useWorker: false,
            minRadius : 35,
            maxRadius : 55,
            gravity: 1.1,
            scaling: 1.8,
            roam: 'move',
            nodes:[
                {category:0, name: '{{request_node_name_envi}}', ip:'{{request_node_name_ip}}', value : 30, label: '{{request_node_name_envi}}',
                   itemStyle: {
                        normal: {
                            label: {
                                textStyle: {
                                    color: 'black',
                                    fontSize: 10
                                  
                                }
                            }
                        }
                    }
                },
                {% autoescape off %}
	            {% for target in target_info_list %}
	            	{category:1, {{ target }}, value : 20,
	            	    itemStyle: {
                        normal: {
                            label: {
                                textStyle: {
                                    color: 'black',
                                    fontSize: 7
                                  }
                                }
                            }
                        }
	            	},
	            {% endfor %}
	            {% endautoescape %}   
            ],
           links : [
	            {% for target in target_list %}
	            	{source : '{{request_node_name_envi}}', target : '{{ target }}', weight :1},
	            {% endfor %} 
                
            ]
        }
    ]
};

        // 为echarts对象加载数据 
        myChart.setOption(option); 
		
		
var ecConfig = require('echarts/config');
function focus(param) {
    var data = param.data;
    var links = option.series[0].links;
    var nodes = option.series[0].nodes;
    if (
        data.source != null
        && data.target != null
    ) { //点击的是边
        var sourceNode = nodes.filter(function (n) {return n.name == data.source})[0];
        var targetNode = nodes.filter(function (n) {return n.name == data.target})[0];
        console.log("选中了边 " + sourceNode.name + ' -> ' + targetNode.name + ' (' + data.weight + ')');
    } else { // 点击的是点
        console.log("选中了" + data.name + '(' + data.value + ')');
    }
}
myChart.on(ecConfig.EVENT.CLICK, focus)

myChart.on(ecConfig.EVENT.FORCE_LAYOUT_END, function () {
    console.log(myChart.chart.force.getPosition());
});

function eConsole(param) {
	var nodeName = param.name.split("|")[0];
	nodeName = $.trim(nodeName);
	window.location.href='/application_tree_'+nodeName+'/';
}

		//myChart.on(ecConfig.EVENT.CLICK, eConsole);
		myChart.on(ecConfig.EVENT.DBLCLICK, eConsole);
		//myChart.on(ecConfig.EVENT.HOVER, eConsole);
		myChart.on(ecConfig.EVENT.DATA_ZOOM, eConsole);
		myChart.on(ecConfig.EVENT.LEGEND_SELECTED, eConsole);
		myChart.on(ecConfig.EVENT.MAGIC_TYPE_CHANGED, eConsole);
		myChart.on(ecConfig.EVENT.DATA_VIEW_CHANGED, eConsole);

		
		}
		);
		
		
    </script>
    <div style = "margin: 0; font-size: 11px; text-align: right; color: #487858;">
		<a href="/upload_file/">| 文件上传</a> |
		<a href="/system_detail/">系统详情页</a> |
		<a href="/version_detail/">版本详情页</a> |
		<a href="/wiki_index/">系统百科页</a> |
		<a href="/dataex_detail/">交互信息展示页</a> |
		<a href="/cm_baseline/">基线展示页</a> |
		<a href="/cm_bi_index/">报表展示页</a> |
		<a href="/test_report_index/">测试周报页</a> |
	</div>
</body>